#ifndef BLOGDETAILSPAGE_H
#define BLOGDETAILSPAGE_H

#include <QWidget>
#include <QLabel>
#include <QTextEdit>
#include <QPushButton>
#include <QListWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMessageBox>
#include <QScrollArea>
#include <QTextBrowser>
#include <QTimer>
#include <QFileDialog>
#include "dataModel/BlogDetail.h"
#include "component/CommentListWidget.h"
#include "component/item/AvatarLabel.h"
#include "component/InputDialog.h"

class BlogDetailsPage : public QWidget
{
    Q_OBJECT
public:
    explicit BlogDetailsPage(QWidget *parent = nullptr);
    void setTitle(const QString &title);
    void setContent(const QString &htmlContent);
    void setByDataModel(const BlogDetail &blogDetail);
    void setEditAndDeleteButtonVisible(bool isVisible);
    void setDownloadButtonVisible(bool isVisible);
    void clearComment();

private:
    void setupUI(); // 初始化 UI
    void setupUIButtonStyle();
    void connectSignals(); // 连接信号与槽

    void updateButtonStyle(QPushButton *button, bool isActive);

    bool isUserBanned();

    QLabel *titleLabel; // 标题
    QLabel *infoLabel;  // 更新时间、阅读量、分类

    QPushButton *editButton;
    QPushButton *deleteButton;

    QPushButton *userButton;   // 头像 + 用户名 合并按钮
    QPushButton *followButton; // 关注按钮

    QTextBrowser *contentBrowser;   // 富文本内容
    QPushButton *downloadButton;    // 附件下载
    QPushButton *likeButton;        // 点赞
    QPushButton *commentButton;     // 评论
    QPushButton *collectButton;     // 收藏
    QPushButton *reportButton;      // 举报
    CommentListWidget *commentList; // 评论列表

    int likeCount;
    int commentCount;
    int favoriteCount;

    bool isFollowed = false;  // 关注状态
    bool isLiked = false;     // 点赞状态
    bool isCollected = false; // 收藏状态

    bool isBan;

private slots:
    void onDownloadClicked();
    void onLikeClicked();
    void onCommentClicked();
    void onCollectClicked();
    void onReportClicked();
    void onFollowClicked();
    void onAuthorClicked();
    void onEditClicked();

signals:
    void authorProfileRequested();
    void editRequested(QString title, QString htmlContent);
};

#endif // BLOGDETAILSPAGE_H
